﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Newtonsoft.Json.Converters;
using Zyg.SSO.Core.Business;

namespace Zyg.SSO.Web.Admin.Account
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class ExistAccount : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "application/json";

            string email = context.Request.QueryString["email"];

            if (string.IsNullOrEmpty(email))
            {
                context.Response.Write("{exist: false}");
                return;
            }
            /*
            string strJSON = System.Web.HttpContext.Current.Server.UrlDecode(context.Request.Form.ToString());

            Zyg.SSO.Core.Business.Account account = Newtonsoft.Json.JsonConvert.DeserializeObject(strJSON, typeof(Zyg.SSO.Core.Business.Account)) as Zyg.SSO.Core.Business.Account;

            */

            if (Zyg.SSO.Core.Business.Account.Exist(email))
            {
                context.Response.Write("{exist: true}");
            }
            else
            {
                context.Response.Write("{exist: false}");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
